﻿using System;
using System.Collections.Generic;
using System.Drawing;
using Simple3DRedactor.Domain;

namespace SceneRedactor
{
    abstract class GeometryView<T> : ObjectView<T> where T : Geometry
    {
        private List<Color> availableAmbientColors = new List<Color> { Color.Black, Color.White, Color.Green, Color.Red };
        private List<Color> availableDiffuseColors = new List<Color> {Color.Black, Color.White, Color.Green, Color.Red};
        private List<Color> availableSpecularColors = new List<Color> { Color.Black, Color.White, Color.Green, Color.Red }; 

        protected GeometryView(T obj) : base(obj)
        {
        }

        public override void ShowProperties(SimpleSceneRedactor redactor)
        {
            base.ShowProperties(redactor);

            // TODO : add Material and Texture Properties

            redactor.ambientComboBox.DataSource = availableAmbientColors;
            redactor.diffuseColorComboBox.DataSource = availableDiffuseColors;
            redactor.specularComboBox.DataSource = availableSpecularColors;

            redactor.ambientComboBox.SelectedIndex = availableAmbientColors.FindIndex(c => c == InnerObject.Material.Ambient);
            redactor.diffuseColorComboBox.SelectedIndex =
                availableDiffuseColors.FindIndex(c => c == InnerObject.Material.Diffuse);
            redactor.specularComboBox.SelectedIndex = availableSpecularColors.FindIndex(c => c == InnerObject.Material.Specular);
        }

        public override void SaveProperties(SimpleSceneRedactor redactor)
        {
            base.SaveProperties(redactor);

            // TODO : add Material and Texture Properties

            var material = new Material();

            if (redactor.ambientComboBox.SelectedIndex > -1)
                material.Ambient = availableAmbientColors[redactor.ambientComboBox.SelectedIndex];

            if (redactor.diffuseColorComboBox.SelectedIndex > -1)
                material.Diffuse = availableDiffuseColors[redactor.diffuseColorComboBox.SelectedIndex];

            if (redactor.specularComboBox.SelectedIndex > -1)
                material.Specular = availableSpecularColors[redactor.specularComboBox.SelectedIndex];

            InnerObject.Material = material;
        }
    }
}
